<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 求该数组中大于平均值的数的个数，和小于平均值的个数。
      //   let arr = [6, 3, 9, 22, 16, 4, 7, 66]
      //   let maxArr = 0
      //   let minArr = 0
      //   let arr1 = 0
      //   let sum = 0
      //   for(let i = 0 ;i <arr.length;i++){
      //     sum+=arr[i]
      //     arr1=sum/arr.length
      //   }
      //   for(let j = 0; j < arr.length; j++){
      //     if(arr[j]>arr1){
      //       maxArr++
      //     }else if(arr[j]<arr1){
      //       minArr++
      //     }
      //   }
      //   console.log(sum);
      //   console.log(arr1);
      //   console.log(maxArr);
      //   console.log(minArr);

      let arr = [6, 3, 9, 22, 16, 4, 7, 66]
      let sum =
        arr.reduce((prev, item) => {
          return prev + item
        }, 0) / arr.length
      console.log(sum)

      let maxArr = arr.reduce((prev, item) => {
        item > sum ? prev++ : prev
        return prev
      }, 0)
      let minArr = arr.length - maxArr
      console.log([maxArr, minArr])
    </script>
  </body>
</html>
